﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using GraphAPI.Model;
using GraphAPI;

namespace Ostovnoe
{
	public partial class OstovnoeControl : UserControl
	{
		Graph oldGraph;
		public OstovnoeControl(Graph graph)
		{
			InitializeComponent();
			oldGraph = graph;
			graphPanel1.Graph = FindOst(graph);
			graphPanel1.ReadOnly = true;
		}

		private Graph FindOst(Graph gr)
		{
			Graph graph;
			graph = gr;
			

			int[] mark = new int[gr.EntityCount];
			for (int i = 0; i < gr.EntityCount; i++)
				mark[i] = i;

			List<int> u0 = new List<int>();

			int su = 0;

			try
			{
				while (u0.Count < gr.EntityCount - 1)
				{
					Relation r = gr.Relations[su];
					int x = gr.GetEntityId(r.StartEntity);
					int y = gr.GetEntityId(r.EndEntity);
					if (mark[x] != mark[y])
					{
						u0.Add(su);
						int z = mark[y];
						for (int i = 0; i < gr.EntityCount; i++)
							if (mark[i] == z)
								mark[i] = mark[x];
					}
					su++;
				}
			}
			catch
			{
				
			}

			foreach (int iRel in u0)
			{
				gr.Relations[iRel].ColorMark = Color.Blue;
			}

			return gr;
		}

	}
}
